﻿using System;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;


    public partial class ADList : AdminBase
    {
        public int classId;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                myDatabind();

            }
        }


        private void myDatabind()
        {

       

            //if (classId != 0)
            //{
                using (Entities bll = new Entities())
                {
                    //var myNew = PredicateBuilder.True<L_Newss>();
                  //  var query = QueryBuilder.Create<L_Newss>();
                    // IQueryable<L_Newss> query = bll.L_Newss;

                    var Bpl = bll.L_AD.OrderByDescending(p => p.NID);

 

                    PagedDataSource pds = new PagedDataSource();
                    pds.DataSource = Bpl.ToList();  //这里好像一定要Tolist();不然会有点错误；
                    pds.AllowPaging = true;
                    AspNetPager1.RecordCount = Bpl.Count(); //记录总数；
                    pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                    pds.PageSize = AspNetPager1.PageSize;

                    this.rptList.DataSource = pds;
                    this.rptList.DataBind();
                }
            //}

        }



        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {   //当页面页数改变时，执行这个方法；
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            myDatabind();
        }
        protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int id = Convert.ToInt32(e.CommandArgument);


            Entities bll = new Entities();
            L_AD model = bll.L_AD.First(p => p.NID == id);

            switch (e.CommandName.ToLower())
            {
                case "ibtntop":
                    if (model.IsTop == true)
                        model.IsTop = false;
                    else
                        model.IsTop = true;
                    break;
                case "ibtnred":
                    if (model.IsRed == true)
                        model.IsRed = false;
                    else
                        model.IsRed = true;
                    break;
                case "ibtnhot":
                    if (model.IsHot == true)
                        model.IsHot = false;
                    else
                        model.IsHot = true;
                    break;
                case "ibtnslide":
                    if (model.IsSlide == true)
                        model.IsSlide = false;
                    else
                        model.IsSlide = true;
                    break;
                case "ibtnlock":
                    if (model.IsLock == true)
                        model.IsLock = false;
                    else
                        model.IsLock = true;
                    break;
              

                case "del":
               //     bll.DeleteObject(model);
                    break;

            }

            bll.SaveChanges();
            myDatabind();
            //RptBind("Id>0" + CombSqlTxt(this.kindId, this.classId, this.keywords, this.property), "AddTime desc");
        }


        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            myDatabind();
        }

        protected void ddlProperty_SelectedIndexChanged(object sender, EventArgs e)
        {
            myDatabind();
        }

    }

